package com.eeepay.eeepay_v2._recadapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.eeepay.eeepay_v2.R;

import cn.eeepay.api.grpc.nano.ManagementCenterProto;

/**
 * 描述：邀请好友奖励明细的适配器
 * 作者：zhuangzeqin
 * 时间: 2017/8/21-14:03
 * 邮箱：zzq@eeepay.cn
 */
public class InvPriMerInfoListRecordAdapter extends CommRecyclerBaseAdater<ManagementCenterProto.InvitePrizesMerchantInfoRecord> {
    public InvPriMerInfoListRecordAdapter(@NonNull Context mContext) {
        super(mContext);
    }

    @Override
    public int getViewType(int position) {
        return 0;
    }

    @Override
    public int getItemLayoutId(int ViewType) {
        return R.layout.item_yqgl_list;
    }

    @Override
    public void onBindView(CommonViewHolder holder, ManagementCenterProto.InvitePrizesMerchantInfoRecord model, int position, int viewType) {
        if (model == null) return;
        holder.setText(R.id.tv_commoditycodeValue, model.merchantNo);//商品编号
        String mobilePhone = model.mobilePhone;
        if (!TextUtils.isEmpty(mobilePhone) && mobilePhone.length()>=11)
        {
            mobilePhone= mobilePhone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
        }
        holder.setText(R.id.tv_invitePhone, mobilePhone);//手机号
        holder.setText(R.id.tv_inviteTime, model.createTime);//创建时间
        holder.setText(R.id.tv_bonusValue, "￥"+model.prizesAmount);//奖励金额
        TextView transactionstate = (TextView) holder.getItemView().findViewById(R.id.tv_transactionstate);//收益状态

        String accountStatus = model.accountStatus; //根据状态标识 tv_bonus 奖励金额:or奖励已入账:
        if (accountStatus.equals("2"))//入账失败 变换背景颜色
        {
            holder.setText(R.id.tv_bonus, "奖励金额:");
            holder.setText(R.id.tv_transactionstate, model.accountStatusZh);//0 未入账, 1 已入账,2 入账失败
            transactionstate.setVisibility(View.VISIBLE);
            transactionstate.setBackgroundResource(R.drawable.ygb);
            transactionstate.setTextColor(mContext.getResources().getColor(R.color.unify_grounding_white));
        }
        else if (accountStatus.equals("0"))//0 未入账
        {
            holder.setText(R.id.tv_bonus, "奖励金额:");
            transactionstate.setVisibility(View.VISIBLE);
            holder.setText(R.id.tv_transactionstate, model.accountStatusZh);//0 未入账, 1 已入账,2 入账失败
            transactionstate.setBackgroundResource(R.drawable.drz);
        }else//已入账
        {
            holder.setText(R.id.tv_bonus, "奖励已入账:");
            transactionstate.setVisibility(View.GONE);
        }


    }
}
